package com.network.service.impl;

import com.network.pojo.Result;
import com.network.pojo.User;
import com.network.service.LoginService;
import com.network.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class LoginServiceImpl implements LoginService {
    private final RestTemplate restTemplate;

    @Autowired
    public LoginServiceImpl(RestTemplate restTemplate) {
        this.restTemplate = restTemplate;
    }

    @Autowired
    private UserService userService;

    @Override
    public Result loginToServer(User user) {
        String url = "http://localhost:8080/login";

        // 发送POST请求
        Result result = restTemplate.postForObject(url, user, Result.class);

        // 处理响应
        if (result.getCode().equals(1)) {
            System.out.println("登录成功");
            return Result.success();
        } else {
            System.out.println("登录失败: " + result.getMsg());
            return Result.error("登录失败");
        }
    }


}
